package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.sys.model.vo.SysUserVo;
import ysq.xyg.sys.service.SysUserService;
import ysq.xyg.web.model.po.WebArea;
import ysq.xyg.web.model.vo.WebAreaVo;
import ysq.xyg.web.service.WebAreaService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 业务模块-活动室信息controller层
 *
 * @author shengQiang yu
 * @date 2019-5-15 22:39:09
 */
@RestController
public class WebAreaController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebAreaController.class);
    @Resource
    private WebAreaService webAreaService;
    @Resource
    private SysUserService sysUserService;
    private WebArea webArea;

    /**
     * 分页查询
     *
     * @param webAreaVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-5-15 22:39:09
     */
    @BaseLog(module = "业务模块",className = "活动室信息",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArea/page",method = RequestMethod.POST)
    public ReturnEntity page(HttpServletRequest request, WebAreaVo webAreaVo, int pageSize, int pageNum){
        SysUser sysUser = acceptCurrentUser(request);
        sysUser=sysUserService.selectByPrimaryKey(sysUser.getId());
        if(BaseConstant.BASE_USER_TYPE_GLY.equals(sysUser.getUserType())){
            webAreaVo.setUserId(sysUser.getId());
        }
        ReturnEntity returnEntity = webAreaService.page(webAreaVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-15 22:39:09
     */
    @RequestMapping(value = "/webArea/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webAreaUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webArea = webAreaService.selectByPrimaryKey(id);
            view.addObject("webArea", webArea);
        }
        List<SysUser> sysUserList=sysUserService.acceptList(new SysUserVo(BaseConstant.BASE_USER_TYPE_GLY,BaseConstant.BASE_STATUS_NORMAL));
        view.addObject("sysUserList", sysUserList);
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-15 22:39:09
     */
    @BaseLog(module = "业务模块",className = "活动室信息",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArea/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webAreaService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webAreaVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-15 22:39:09
     */
    @BaseLog(module = "业务模块",className = "活动室信息",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArea/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebAreaVo webAreaVo){
        return webAreaService.addOrUpdate(webAreaVo,acceptCurrentUser(request));
    }
}